<template>
<!--pages/login/login.ttml-->
 <view class="content">
   <view class="account">
     <view class="title">账号</view>
     <view class="num"><input @input="accountInput" placeholder="用户名/邮箱/手机号" placeholder-style="color:#999999;" /></view>
   </view>
   <view class="hr"></view>
   <view class="account">
     <view class="title">密码</view>
     <view class="num"><input @blur="pwdBlur" placeholder="请输入密码" password placeholder-style="color:#999999;" /></view>
     <view class="see">
       <image src="/static/images/see.gif" style="width:35px;height:30px;"></image>
     </view>
   </view>
 <view class="hr"></view>
 <button class="btn" :disabled="disabled" :type="btnstate" @tap="login">登录</button>
 <view class="operate">
   <!-- <view><navigator url="../mobile/mobile">手机快速注册</navigator></view> -->
   <view><navigator url="../company/company">企业用户注册</navigator></view>
 </view>

 </view>
</template>

<script>
let app = getApp();

export default {
  data() {
    return {
      disabled: true,
      btnstate: "default",
      account: "",
      password: ""
    };
  },

  components: {},
  props: {},
  methods: {
    accountInput: function (e) {
      var content = e.detail.value;
      uni.setStorageSync('content', content);

      if (content != "") {
        this.setData({
          disabled: false,
          btnstate: "primary",
          account: content
        });
      }
    },
    pwdBlur: function (e) {
      var password = e.detail.value;
      uni.setStorageSync('password', password);

      if (password != "") {
        this.setData({
          password: password
        });
      }
    },
    login: function () {
      uni.request({
        // url: `https://we9.91gongju.cn:10000/user/login`,
        url: `${app.globalData.baseUrl}/user/login`,
        //url: `https://localhost:10000/user/login`,
        // 目标服务器url
        method: 'POST',
        dataType: 'json',
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          username: uni.getStorageSync('content'),
          password: uni.getStorageSync('content')
        },
        success: res => {
          let code = res.data.code;
          console.log(code);

          if (code === 200) {
            uni.reLaunch({
              url: `../../card/square/square`
            });
          }
        }
      });
    }
  }
};
</script>
<style>

 .content{
   margin-top: 40px;
 }
 .account{
   display: flex;
   flex-direction: row;
   padding-left: 20px;
   padding-top: 20px;
  padding-bottom: 10px;
  width: 90%;
}
.title{
  margin-right: 30px;
  font-weight: bold;
}
.hr{
  border: 1px solid #cccccc;
  opacity: 0.2;
  width: 90%;
  margin: 0 auto;
}
.see{
  position: absolute;
  right: 20px;
}
.account{
   display: flex;
   flex-direction: row;
   padding-left: 20px;
   padding-top: 20px;
   padding-bottom: 10px;
   width: 90%;
 }
 .title{
   margin-right: 30px;
   font-weight: bold;
 }
 .hr{
   border: 1px solid #cccccc;
   opacity: 0.2;
   width: 90%;
   margin: 0 auto;
 }
 .see{
   position: absolute;
   right: 20px;
 }
 .btn{
   width: 90%;
   margin-top: 40px;
   color: #999999;
 }
 .operate{
   display: flex;
   flex-direction: row; 
 }
 .operate view{
   margin: 0 auto;
   margin-top: 40px;
   font-size: 14px;
   color: #333333;
 }
 .login{
   display: flex;
   flex-direction: row;
   margin-top: 150px;
 }
 .login view{
   margin: 0 auto;
 }
</style>